<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<%@page isELIgnored="false" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport"
          content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <title><spring:message code="title"/></title>
    <meta name="Keywords" content="南通大学，通大">
    <meta name="Description" content="南通大学，通大">


</head>
<body>
<div id="particles">

    <div class="intro">
        <div class="container">
            <div class="row" style="padding: 50px;">
                <div class="col-md-3 col-centered ">
                    <h3 style="color:black"><spring:message code="login-title"/></h3>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 col-sm-8 col-centered">
                    <form method="post" id="form"
                          action="${pageContext.request.contextPath}/user/login${style}"
                          class="nice-validator n-default">
                        <div class="form-group validator-tips">
                            <input type="text" class="form-control" id="email" name="email"
                                   placeholder="<spring:message code="placeholder.email"/> " required="required">
                            <div class="error email-null" hidden>
                                <spring:message code="email-null"/>
                            </div>
                            <div class="error email-error" hidden>
                                <spring:message code="email-error"/>
                            </div>
                        </div>
                        <div class="form-group validator-tips">
                            <input type="password" class="form-control" id="rinpsipd" name="rinpsipd"
                                   placeholder="<spring:message code="placeholder.rinpsipd"/>" required="required">
                            <div class="error rinpsipd-null" hidden>
                                <spring:message code="rinpsipd-null"/>
                            </div>
                        </div>
                        <div class="form-group validator-tips">
                            <div class="error login-error" hidden>
                                <spring:message code="login-error"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <a href="${pageContext.request.contextPath}/register.pj"><spring:message
                                    code="quick-register"/> </a>
                        </div>
                    </form>
                </div>
            </div>
            <div class="row">
                <div class="col-md-4 col-sm-8 col-centered">

                    <div class="form-group">
                        <input type="button" id="submit_button"
                               class="form-control btn btn-primary btn-current"
                               value="<spring:message code="login"/>">
                    </div>
                    <div class="form-group">
                        <a href="#" class="form-control btn btn-default btn-current"><spring:message
                                code="cancel"/> </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">

    if ("${msg}" == "0001")
        $('.login-error').show();
    else
        $('.login-error').hide();

    if ("${msg}" == "0002") {
        swal({
            title: "<spring:message code="login.register.title"/>",
            text: "<spring:message code="login.register.content"/>",
            animation: "slide-from-bottom",
            imageUrl: "${pageContext.request.contextPath}/static/images/thumbs-up.jpg"
        });
    }

    if ("${msg}" == "0003") {
        swal({
                    title: "<spring:message code="login.active.title"/> ",
                    text: "<spring:message code="login.active.content"/> ",
                    type: "warning",
                    animation: "slide-from-bottom",
                    showCancelButton: true,
                    confirmButtonColor: "#DD6B55",
                    confirmButtonText: "<spring:message code="login.active.send"/> ",
                    cancelButtonText: "<spring:message code="login.active.newEmail"/> ",
                    closeOnConfirm: false,
                    closeOnCancel: false
                }, function (isConfirm) {
                    if (!isConfirm) {
                        swal({
                                    title: "<spring:message code="email-null"/> ",
                                    type: "input",
                                    showCancelButton: true,
                                    closeOnConfirm: false,
                                    animation: "slide-from-top",
                                    inputPlaceholder: "<spring:message code="placeholder.email"/> "
                                }, function (inputValue) {
                                    var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
                                    if(!myreg.test(inputValue)) {
                                        swal.showInputError("<spring:message code="email-error"/> ");
                                        return false;
                                    }
                                    send(inputValue);
                                }
                        );
                    }else{
                        send("");
                    }

                }
        );
    }

    if ("${msg}" == "0004") {
        swal({
            title: "<spring:message code="login.register.title"/>",
            text: "<spring:message code="login.active.success.content"/>",
            animation: "slide-from-bottom",
            imageUrl: "${pageContext.request.contextPath}/static/images/thumbs-up.jpg"
        });
    }

    function send(email){
        $.get("${pageContext.request.contextPath}/user/send.ztc",
                {email: email},
                function (data) {
                    if (data.result == "success") {
                        swal("<spring:message code="login.send"/> ",
                                "<spring:message code="login.register.content"/> ",
                                "success");
                    } else {
                        swal("<spring:message code="login.send"/> ",
                                "<spring:message code="error.active"/> ",
                                "error");
                    }
                });
    }

    $(document).ready(function () {
        $('#particles').particleground({
            dotColor: 'rgba(52, 152, 219, 0.36)',
            lineColor: 'rgba(52, 152, 219, 0.86)',
            density: 130000,
            proximity: 500,
            lineWidth: 0.2
        });


        $('#submit_button').click(function () {
            var email = $('#email').val().trim();
            var myreg = /^([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+@([a-zA-Z0-9]+[_|\_|\.]?)*[a-zA-Z0-9]+\.[a-zA-Z]{2,3}$/;
            var rinpsipd = $('#rinpsipd').val().trim();
            if (email == '') {
                $('.email-null').show();
                return;
            } else {
                $('.email-null').hide();
            }

            if (!myreg.test(email)) {
                $('.email-error').show();
                return;
            } else
                $('.email-error').hide();

            if (rinpsipd == '') {
                $('.rinpsipd-null').show();
                return;
            } else {
                $('.rinpsipd-null').hide();
            }

            $('#form').submit();

        });

    });
</script>
</body>
</html>
